package com.rc.saas.tenant.controller.channel;

import com.rc.saas.tenant.common.vo.TResponse;
import com.rc.saas.tenant.model.enterprise.EnterpriseMember;
import com.rc.saas.tenant.model.member.MemberInfo;
import com.rc.saas.tenant.model.member.RcMemberFlag;
import com.rc.saas.tenant.service.enterprise.EnterpriseMemberService;
import com.rc.saas.tenant.service.member.MemberInfoService;
import com.rc.saas.tenant.service.member.RcMemberFlagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/channel")
public class ChannelController {

    @Autowired
    private MemberInfoService memberInfoService;

    @Autowired
    private EnterpriseMemberService enterpriseMemberService;

    private RcMemberFlagService memberFlagService;

    @RequestMapping("/detail")
    public String detail(Model model, Long memberId, Long enterpriseId) {
        EnterpriseMember enterprise = enterpriseMemberService.selectByPrimaryKey(enterpriseId);
        MemberInfo memberInfo = memberInfoService.selectByPrimaryKey(memberId);
        model.addAttribute("enterprise", enterprise);
        model.addAttribute("member", memberInfo);
        return "/templates/system/content";
    }

    @RequestMapping("/del/{id}")
    public TResponse delChannel(@PathVariable("id") Long id) {
        RcMemberFlag memberFlag = memberFlagService.selectByPrimaryKey(id);
        memberFlag.setIsChannelLevel("0");
        memberFlagService.updateByPrimaryKeySelective(memberFlag);
        return TResponse.SUCCESS();
    }
}
